{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "using Gadfly\n",
    "using Colors\n",
    "\n",
    "######################## Function for saving plots #################################\n",
    "# Input:\n",
    "# fileName = Name of the file where the plot is to be stored\n",
    "#            (with or without extension)\n",
    "# f_e = Array containing function evaluations as columns for each solver\n",
    "# err = Array containing erros as columns for each solver\n",
    "# solverNames = Array containing the names of solvers used in respective order\n",
    "# plotSize = size of the plot to be created\n",
    "# \n",
    "# Values have been tuned for a graph similar to the one in \n",
    "# Solving Ordinary Differential Equations I by\n",
    "# Hairer, Ernst, Nørsett, Syvert P., Wanner, Gerhard\n",
    "# page: 252\n",
    "###################################################################################\n",
    "function savePlotPNG(fileName,f_e,err,solverNames,\n",
    "    plotSize=[30cm,30cm])\n",
    "    \n",
    "    numOfLayers = length(solverNames);\n",
    "    \n",
    "    if !contains(fileName,\".\")\n",
    "        fileName = string(fileName,\".png\");\n",
    "    end\n",
    "    \n",
    "    plotColorsHex = [\"#4D4D4D\",\"#5DA5DA\",\"#FAA43A\",\"#60BD68\",\n",
    "        \"#F17CB0\",\"#B2912F\",\"#B276B2\", \"#DECF3F\",\"#F15854\"];\n",
    "    plotColors = [parse(Colorant,c) for c in plotColorsHex];\n",
    "    \n",
    "    majorFontSize = 24pt;\n",
    "    minorFontSize = 20pt;\n",
    "    pointSize = 5pt;\n",
    "    \n",
    "    myplot = plot(Scale.x_log10,Scale.y_log10,\n",
    "        Coord.cartesian(xflip=true),\n",
    "        Guide.manual_color_key(\"Legend\",solverNames,plotColorsHex[1:numOfLayers]),\n",
    "        Guide.xlabel(\"error\"),Guide.ylabel(\"#Function Evaluations\"),\n",
    "        Theme(major_label_font_size=majorFontSize,panel_stroke=colorant\"black\",\n",
    "        minor_label_font_size=minorFontSize,key_title_font_size=majorFontSize,\n",
    "        key_label_font_size=minorFontSize,key_position=:top,key_max_columns=1));\n",
    "    \n",
    "    for i = 1:numOfLayers\n",
    "        push!(myplot,layer(x=err[:,i],y=f_e[:,i],Geom.point,Geom.path,\n",
    "        Theme(default_color=plotColors[i],default_point_size=pointSize)));\n",
    "    end\n",
    "    \n",
    "    draw(PNG(fileName,plotSize[1],plotSize[2]),myplot)\n",
    "    return nothing\n",
    "end"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.4.2",
   "language": "julia",
   "name": "julia-0.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.4.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
